// Show how many days are left till christmas
// By DreamVB 02:30 18/09/2016

#include <iostream>
#include <time.h>
#include <Windows.h>
#include <ctime>

using namespace std;
using std::cout;
using std::endl;

int DaysTillXmas(int year){
	const int SecondsInDay = 86400;

	int daysleft = 0;
	tm date1 = { 0 };
	tm date2 = { 0 };

	//Get system date and time.
	SYSTEMTIME st;
	::GetSystemTime(&st);
	
	//Set christmas date.
	date1.tm_mday = 25;
	date1.tm_mon = 12 - 1;
	date1.tm_year = year - 1900;

	//Current system date.
	date2.tm_mday = st.wDay;
	date2.tm_mon = st.wMonth - 1;
	date2.tm_year = st.wYear - 1900;

	//Make times for christmas and current
	time_t time1 = mktime(&date1);
	time_t time2 = mktime(&date2);
	//Work out the days we have left.
	daysleft = (int)difftime(time1, time2);
	daysleft /= SecondsInDay;
	//Return number of days left
	return daysleft;
}

int main(int argc, char *argv[]){
	//Write how many days are left
	cout << "There are " << DaysTillXmas(2016) << 
		" days left till christmas 2016" << endl;

	system("pause");
	return 0;
}